package com.itheima.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/sessionlong")
public class SessionLongServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      //想要持久化jessionid 怎么做呢
        System.out.println("先获取我们session 如果有就获取 ，没有就新建");
        HttpSession session = request.getSession();
        System.out.println("当前session对象的id是:"+session.getId());
        //我们 之前的jsession遵循默认规则  我们可以显性化
        Cookie jsessionid = new Cookie("JSESSIONID", session.getId());
        jsessionid.setMaxAge(60*10);
        jsessionid.setPath(request.getContextPath());//设置路径为项目路径
        //存到响应头
        response.addCookie(jsessionid);

        response.getWriter().write("see this session："+session.getId());

    }
}
